package Utils;

import java.util.GregorianCalendar;

/**
 *
 * @author Administrator
 */
public class TimeFormat {
	public static String gregorian_to_string(GregorianCalendar cal) {
		String year = cal.get(GregorianCalendar.YEAR)+"";
		String month = cal.get(GregorianCalendar.MONTH)+"";
		month = month.length() == 1 ? "0"+month : month;
		String day = cal.get(GregorianCalendar.DAY_OF_MONTH)+"";
		day = day.length() == 1 ? "0"+day : day;
		return year+"-"+month+"-"+day;
	}

	public static GregorianCalendar string_to_gregorian(String date) {
		String[] chunks = date.split("-");
		int year = Integer.parseInt(chunks[0]);
		int month = Integer.parseInt(chunks[1]);
		int day = Integer.parseInt(chunks[2]);
		return new GregorianCalendar(year, month, day);
	}
}
